package com.snailvr.tv.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.snail.readyvr.R;

import java.util.List;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

/**
 * Created by Administrator on 2017/2/16.
 */

public class PhraseViewAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<String> mStrings;
    public PhraseViewAdapter(Context context, List<String> stringList) {
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
        mStrings = stringList;
        if (mStrings.size() == 0) {
            mStrings.add(0,"");
        }
    }

    @Override
    public int getCount() {
        return mStrings.size();
    }

    @Override
    public String getItem(int position) {
        return mStrings.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.layout_phrase_item,null,false);
            viewHolder = new ViewHolder();
            viewHolder.mTextView = (TextView)convertView.findViewById(R.id.text_view_phrase);
            viewHolder.mImage_add = (ImageView) convertView.findViewById(R.id.img_view_add_normal);
            viewHolder.mLayout = (RelativeLayout) convertView.findViewById(R.id.layout_add_phrase);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.mTextView.setText(mStrings.get(position));
        if(position==0) {
            viewHolder.mLayout.setVisibility(VISIBLE);
            viewHolder.mImage_add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // jump to Phrase Edit Dialog;
                }
            });


        } else {
            viewHolder.mLayout.setVisibility(GONE);
        }
        return convertView;
    }

    static class ViewHolder {
        TextView mTextView;
        ImageView mImage_add;
        RelativeLayout mLayout;

    }
}
